package proxy_jdk;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @ClassName HuGeProxy1
 * @Date 2021/7/27 10:18
 * @Author 李明杰
 * @Description
 */

public class HuGeProxy1 implements InvocationHandler {
    private Huge huge;

    //动态代理需要传入
    public void setHuge(Huge huge) {
        this.huge = huge;
    }

    public Star getProxy() {
        return (Star) Proxy.newProxyInstance(getClass().getClassLoader(), huge.getClass().getInterfaces(), this);
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

        System.out.println("我是胡歌代理一号，有事找我");

        return method.invoke(huge, args);
    }
}
